package com.eedi.org.healthinfo.controller;

import com.eedi.framework.common.enums.CommonStatusEnum;
import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.common.validation.AddGroup;
import com.eedi.framework.common.validation.UpdateGroup;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoGroupPageReqVO;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoGroupRespVO;
import com.eedi.org.healthinfo.dal.dataobject.OrgHealthInfoGroupDO;
import com.eedi.org.healthinfo.service.OrgHealthInfoGroupService;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoGroupSaveReqVO;
import com.eedi.org.healthinfo.controller.vo.OrgHealthInfoGroupUpdateStatusReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

import static com.eedi.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 健康资讯分类管理")
@RestController
@RequestMapping("/health-info-group")
@Validated
public class OrgHealthInfoGroupController {

    @Resource
    private OrgHealthInfoGroupService orgHealthInfoGroupService;

    @PostMapping("/create")
    @Operation(summary = "创建健康资讯分类管理")
    @PermitAll
   // @PreAuthorize("@ss.hasPermission('org:health-info-group:create')")
    public CommonResult<String> createHealthInfoGroup(@Validated({AddGroup.class}) @RequestBody OrgHealthInfoGroupSaveReqVO createReqVO) {
        return success(orgHealthInfoGroupService.createHealthInfoGroup(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新健康资讯分类管理")
    @PermitAll
    //@PreAuthorize("@ss.hasPermission('org:health-info-group:update')")
    public CommonResult<Boolean> updateHealthInfoGroup(@Validated({UpdateGroup.class}) @RequestBody OrgHealthInfoGroupSaveReqVO updateReqVO) {
        orgHealthInfoGroupService.updateHealthInfoGroup(updateReqVO);
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除健康资讯分类管理")
    @Parameter(name = "orgHealthInfoGroupId", description = "编号", required = true)
    @PermitAll
    //  @PreAuthorize("@ss.hasPermission('org:health-info-group:delete')")
    public CommonResult<Boolean> deleteHealthInfoGroup(String orgHealthInfoGroupId) {
        orgHealthInfoGroupService.deleteHealthInfoGroup(orgHealthInfoGroupId);
        return success(true);
    }

    @PostMapping("/update-status")
    @Operation(summary = "修改健康资讯分类状态")
    //   @PreAuthorize("@ss.hasPermission('org:health-info-group:updateStatus')")
    @PermitAll
    public CommonResult<Boolean> updateHealthInfoGroupStatus(@Valid @RequestBody OrgHealthInfoGroupUpdateStatusReqVO reqVO) {
        orgHealthInfoGroupService.updateHealthInfoGroupStatus(reqVO.getOrgHealthInfoGroupId(), reqVO.getOrgStatus());
        return success(true);
    }


    @GetMapping("/list")
    @Operation(summary = "获得健康资讯分类管理")
    @PermitAll
    //  @PreAuthorize("@ss.hasPermission('org:health-info-group:list')")
    public CommonResult<List<OrgHealthInfoGroupRespVO>> listHealthInfoGroup(CommonStatusEnum status) {
        List<OrgHealthInfoGroupDO> healthInfoGroupList = orgHealthInfoGroupService.listHealthInfoGroup(status);
        return success(BeanUtils.toBean(healthInfoGroupList, OrgHealthInfoGroupRespVO.class));
    }

    @PostMapping("/page")
    @Operation(summary = "获得健康资讯分类管理分页")
    @PermitAll
  //  @PreAuthorize("@ss.hasPermission('org:health-info-group:query')")
    public CommonResult<PageResult<OrgHealthInfoGroupRespVO>> getHealthInfoGroupPage(@RequestBody OrgHealthInfoGroupPageReqVO pageReqVO) {
        PageResult<OrgHealthInfoGroupDO> pageResult = orgHealthInfoGroupService.getHealthInfoGroupPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, OrgHealthInfoGroupRespVO.class));
    }

}
